﻿using Microsoft.Extensions.Logging;
using Sayook.Framework.DbCore.DbConnection;

namespace Sayook.Framework.DbCore.DbContext
{
    /// <summary>
    /// 访问数据库
    /// </summary>
    public abstract class DbContext
    {
        /// <summary>
        /// 数据库连接提供者
        /// </summary>
        protected IDbConnectionProvider _connProvider;

        /// <summary>
        /// 日志记录
        /// </summary>
        protected ILogger _logger;

        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        protected string DbConnectionString => GetDbConnectionString();

        /// <summary>
        /// 获取数据库连接字符串
        /// </summary>
        /// <returns>数据库连接字符串</returns>
        protected abstract string GetDbConnectionString();

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="connProvider">数据库连接</param>
        /// <param name="logger">日志</param>
        public DbContext(IDbConnectionProvider connProvider, ILogger<DbContext> logger)
        {
            _connProvider = connProvider;
            _logger = logger;
        }
    }
}